#include <51func.h>
int main(int argc, char *argv[])
{
    pid_t ret = fork();
    if(ret == 0){
        printf("I am child, ret = %d, pid = %d, ppid = %d\n",
               ret,getpid(),getppid());
        //return -1;
        while(1){
            sleep(1);
        }
    }
    else{
        int status;
        printf("I am parent, ret = %d, pid = %d, ppid = %d\n",
               ret,getpid(),getppid());
        //wait(&status);
        while(1){
            int ret = waitpid(-1,&status,WNOHANG);
            if(ret != 0){
                break;
            }
            else{
                printf("child is not dead yet!\n");
                sleep(2);
            }
        }
        if(WIFEXITED(status)){
            printf("exit normally, return value = %d\n",WEXITSTATUS(status));
        }
        else if(WIFSIGNALED(status)){
            printf("exit abnormally, return value = %d\n", WTERMSIG(status));
        }
    }
}

